Introduce gtkaccelmapprivate.h
authorMatthias Clasen <mclasen@redhat.com>
Mon, 5 Dec 2011 22:37:04 +0000 (17:37 -0500)
committerRyan Lortie <desrt@desrt.ca>
Mon, 19 Dec 2011 17:51:11 +0000 (12:51 -0500)
Move internal accel map API there and update all users.
Also, add an internal function to create an accel path for
an action and parameter, and use it in gtkapplication.c and
gtkmodelmenuitem.c instead of duplicating that code.

gtk/Makefile.am
gtk/gtkaccelmap.c
gtk/gtkaccelmap.h
gtk/gtkaccelmapprivate.h [new file with mode: 0644]
gtk/gtkapplication.c
gtk/gtkmain.c
gtk/gtkmodelmenuitem.c
gtk/gtkwidget.c

index d1cafc53e15272e9ff8c05470dab38dd148258c3..c5cd39a4a1e3dff73bcc1ce1f28df97e9aae2b6d 100644 (file)
@@ -395,6 +395,7 @@ gtk_private_h_sources =             \
        gactionobserver.h       \
        gactionobservable.h     \
        gtkaccelgroupprivate.h  \
+       gtkaccelmapprivate.h    \
        gtkanimationdescription.h \
        gtkappchooserprivate.h  \
        gtkappchoosermodule.h   \
index efc06ba90a278026cc397e1f611db12377b8357e..2f33b92c660c849f771442d1cd2c26a8091642e1 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "config.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 
 #include "gtkmarshalers.h"
 #include "gtkwindowprivate.h"
@@ -1066,3 +1066,20 @@ do_accel_map_changed (AccelEntry *entry)
                   entry->accel_key,
                   entry->accel_mods);
 }
+
+gchar *
+_gtk_accel_path_for_action (const gchar *action_name,
+                            GVariant    *parameter)
+{
+  GString *s;
+
+  s = g_string_new ("<Actions>/");
+  g_string_append (s, action_name);
+  if (parameter)
+    {
+      g_string_append_c (s, '/');
+      g_variant_print_string (parameter, s, FALSE);
+    }
+  return g_string_free (s, FALSE);
+}
+
index dfce2b80c898b0646cd241b550157d50b71b7659..d55318e97d56bfa8a903250f12eed9bc31f33187 100644 (file)
@@ -90,16 +90,6 @@ GType        gtk_accel_map_get_type (void) G_GNUC_CONST;
 GtkAccelMap *gtk_accel_map_get      (void);
 
 
-/* --- internal API --- */
-void           _gtk_accel_map_init             (void);
-
-void            _gtk_accel_map_add_group        (const gchar   *accel_path,
-                                                 GtkAccelGroup *accel_group);
-void            _gtk_accel_map_remove_group     (const gchar   *accel_path,
-                                                 GtkAccelGroup *accel_group);
-gboolean       _gtk_accel_path_is_valid         (const gchar   *accel_path);
-
-
 G_END_DECLS
 
 #endif /* __GTK_ACCEL_MAP_H__ */
diff --git a/gtk/gtkaccelmapprivate.h b/gtk/gtkaccelmapprivate.h
new file mode 100644 (file)
index 0000000..52843af
--- /dev/null
@@ -0,0 +1,45 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1998, 2001 Tim Janik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_ACCEL_MAP_PRIVATE_H__
+#define __GTK_ACCEL_MAP_PRIVATE_H__
+
+
+#include <gtk/gtkaccelmap.h>
+
+G_BEGIN_DECLS
+
+void            _gtk_accel_map_init         (void);
+
+void            _gtk_accel_map_add_group    (const gchar   *accel_path,
+                                             GtkAccelGroup *accel_group);
+void            _gtk_accel_map_remove_group (const gchar   *accel_path,
+                                             GtkAccelGroup *accel_group);
+gboolean        _gtk_accel_path_is_valid    (const gchar   *accel_path);
+
+gchar         * _gtk_accel_path_for_action  (const gchar   *action_name,
+                                             GVariant      *parameter);
+
+G_END_DECLS
+
+#endif /* __GTK_ACCEL_MAP_PRIVATE_H__ */
index 66cb48883c438289daefe60f85d5cebfee45fc14..3ba6bf1ee9f79d2eab3eb31efc5f432b203c68f1 100644 (file)
@@ -31,7 +31,7 @@
 #include "gtkmarshalers.h"
 #include "gtkmain.h"
 #include "gtkapplicationwindow.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 
 #include <gdk/gdk.h>
 #ifdef GDK_WINDOWING_X11
@@ -510,23 +510,6 @@ gtk_application_get_windows (GtkApplication *application)
   return application->priv->windows;
 }
 
-/* keep this in sync with gtkmodelmenuitem.c */
-static gchar *
-get_accel_path (const gchar *action_name,
-                GVariant    *parameter)
-{
-  GString *s;
-
-  s = g_string_new ("<Actions>/");
-  g_string_append (s, action_name);
-  if (parameter)
-    {
-      g_string_append_c (s, '/');
-      g_variant_print_string (parameter, s, FALSE);
-    }
-  return g_string_free (s, FALSE);
-}
-
 /**
  * gtk_application_add_accelerator:
  * @application: a #GtkApplication
@@ -572,7 +555,7 @@ gtk_application_add_accelerator (GtkApplication *application,
       return;
     }
 
-  accel_path = get_accel_path (action_name, parameter);
+  accel_path = _gtk_accel_path_for_action (action_name, parameter);
 
   if (gtk_accel_map_lookup_entry (accel_path, NULL))
     gtk_accel_map_change_entry (accel_path, accel_key, accel_mods, TRUE);
@@ -603,7 +586,7 @@ gtk_application_remove_accelerator (GtkApplication *application,
 
   g_return_if_fail (GTK_IS_APPLICATION (application));
 
-  accel_path = get_accel_path (action_name, parameter);
+  accel_path = _gtk_accel_path_for_action (action_name, parameter);
 
   if (!gtk_accel_map_lookup_entry (accel_path, NULL))
     {
index 25e61ebc47ba3c7b54db7089f65ff9f18f2f4adf..67d843e433fb360b4fbc329ceae93ac19ea932de 100644 (file)
 
 #include "gtkintl.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkbox.h"
 #include "gtkclipboard.h"
 #include "gtkdebug.h"
index 4e2fd09d0f199b1dc8652464e310d082d55d7f56..ed49dafda458c68095055521186cb651bb16dccc 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "gtkmodelmenuitem.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkmodelmenu.h"
 
 struct _GtkModelMenuItem
@@ -189,22 +189,6 @@ gtk_model_menu_item_action_removed (GActionObserver   *observer,
   gtk_widget_queue_resize (GTK_WIDGET (item));
 }
 
-static gchar *
-get_accel_path (const gchar *action_name,
-                GVariant    *parameter)
-{
-  GString *s;
-
-  s = g_string_new ("<Actions>/");
-  g_string_append (s, action_name);
-  if (parameter)
-    {
-      g_string_append_c (s, '/');
-      g_variant_print_string (parameter, s, FALSE);
-    }
-  return g_string_free (s, FALSE);
-}
-
 static void
 gtk_model_menu_item_setup (GtkModelMenuItem  *item,
                            GMenuModel        *model,
@@ -262,7 +246,7 @@ gtk_model_menu_item_setup (GtkModelMenuItem  *item,
       if (state != NULL)
         g_variant_unref (state);
 
-      path = get_accel_path (item->action_name, item->target);
+      path = _gtk_accel_path_for_action (item->action_name, item->target);
       gtk_menu_item_set_accel_path (GTK_MENU_ITEM (item), path);
       g_free (path);
     }
index 962633317b551c738f0ccd740ef0b42a8fb1ae56..28a18fb231fcc4f211a293ba8c24b19c4ec0ef6f 100644 (file)
@@ -35,7 +35,7 @@
 #include <cairo-gobject.h>
 
 #include "gtkcontainer.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkclipboard.h"
 #include "gtkiconfactory.h"
 #include "gtkintl.h"